Skip to main content

QuickNode SDK Core RPC Functions

Updated on
Oct 3, 2023

Overview

The SDK supports Core JSON-RPC API functionality for its supported chains. These functions are provided by viem.

Core RPC Method to SDK Function

The following is a list of supported Core RPC methods and the equivalent viem function available to the SDK. Please see the linked Core RPC method documentation for the example SDK usage, and the linked viem docs for the equivalent function documentation.

Core RPC methodSDK function (from viem)
eth_getBalancegetBalance
eth_getTransactionCountgetTransactionCount
eth_blockNumbergetBlockNumber
eth_getBlockByNumbergetBlock
eth_getBlockByHashgetBlock
eth_getBlockTransactionCountByHashgetBlockTransactionCount
eth_getBlockTransactionCountByNumbergetBlockTransactionCount
eth_subscribewatchBlocks
eth_chainIdgetChainId
eth_estimateGasestimateGas
eth_feeHistorygetFeeHistory
eth_gasPricegetGasPrice
eth_newBlockFiltercreateBlockFilter
eth_newFiltercreateEventFilter
eth_newPendingTransactionFiltercreatePendingTransactionFilter
eth_getFilterChangesgetFilterChanges
eth_getFilterLogsgetFilterLogs
eth_getLogsgetLogs
eth_uninstallFilteruninstallFilter
eth_callcall
eth_getTransactionByHashgetTransaction
eth_getTransactionReceiptgetTransactionReceipt

More helper functions are available for Core RPC calls through viem. For more information about how to utilize viem and its helper functions, see the Viem Integration page.

Example: Get Balance

To call the eth_getBalance RPC method, you can use the getBalance function.

import { Core } from '@quicknode/sdk';

const core = new Core({
endpointUrl: "https://my-endpoint-name.quiknode.pro/myauthtoken/",
});

core.client.getBalance({
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
}).then(balance => console.log(balance))

How to Call RPC Methods Directly

Not all RPC methods have a corresponding function at this time. To call an RPC method directly, the client.request() function can be used.

For example, here is how to call trace_block:

import { Core } from '@quicknode/sdk';

const core = new Core({
endpointUrl: "https://my-endpoint-name.quiknode.pro/myauthtoken/",
});

core.client.request({
method: "trace_block",
params: ["0xccb93d"],
}).then(traceBlock => console.log(traceBlock));

In TypeScript, the RPCSchemaOverride type from viem needs to be passed into the request generic to avoid type errors. Please be aware this function and the response will not have complete type safety.

import { Core, viem } from '@quicknode/sdk';

const core = new Core({
endpointUrl: "https://my-endpoint-name.quiknode.pro/myauthtoken/",
});

core.client.request<viem.RpcSchemaOverride>({
method: "trace_block",
params: ["0xccb93d"],
}).then(traceBlock => console.log(traceBlock));
Share this doc